
*change the directory
clear
set more off
set matsize 10000

log using E:\COVID_governance, replace

* income loss
************************
clear
set more off

use "E:\Cuong - paper\COVID\public_dataset.dta", clear

	
	merge m:1 country region using "E:\Cuong - paper\COVID\coronavirus.dta"
	drop _m
	gen caserate=confirmed/(1000*population)
	
* Ouctome variables
	* drop if gender==3
	gen female=(gender==2)
	
	recode race_black -99=.
	
	for var lost_hh_income expected_fall_own_lab expected_fall_hh_inc: replace X=0 if X<0
	gen double lnlostinc= log(lost_hh_income+ 1)
	gen double lnexpowninc= log(expected_fall_own_lab+ 1)
	gen double lnexphhinc= log(expected_fall_hh_inc+ 1)

	gen workwell=work_from_home_well
	
	gen workchange=0 if work_change_due_pandemic>=1 & work_change_due_pandemic<=3
	replace workchange=1 if work_change_due_pandemic>=1 & work_change_due_pandemic<=2
	tab workchange
	
	gen dinloss=(experienced_fall_hh_income==1)

	gen lost_job0=(lost_job==1 | lost_job==2)
	gen lost_job1=(lost_job==1)
	gen lost_job2=(lost_job==2)
	* for var lost_job0 lost_job1 lost_job2 workwell workchange lnexpowninc : replace X=. if labor_status==4
	
	gen happy=(happiness_these_days>=5)
	gen veryhappy=(happiness_these_days>=6)
	gen unhappy=(happiness_these_days<=2)
	
	tab change_weekly_expenses female , nof col
	
	tab change_savings female , nof col
	
	 gen gov=(industry==8)
	
* Control variables
	drop if income_group==.
	recode income_group 6=.	
	gen qt1= income_group== 1 if income_group<.
	gen qt2= income_group== 2 if income_group<.
	gen qt3= income_group== 3 if income_group<.
	gen qt4= income_group== 4 if income_group<.
	gen qt5= income_group== 5 if income_group<.

	gen exposure_ms= exposure== .

	recode age_group 8=4
	ta age_group, gen(ageg)
	gen urban= current_living_area== 1 
	gen surban= current_living_area== 2
	gen rural= current_living_area== 3

	gen china= country== "china"
	gen italy= country== "italy"
	gen japan= country== "japan"
	gen korea= country== "korea"
	gen uk= country== "uk"
	gen us= country== "us"

	gen group=1 if country== "china"
	replace group=2 if country== "japan"
	replace group=3 if  country== "korea"
	replace group=4 if country== "italy"
	replace group=5 if country== "uk"
	replace group=6 if country== "us"
	
	
	gen gini=40.9 if country== "china"
	replace gini=25.6 if country== "japan"
	replace gini=32.7 if  country== "korea"
	replace gini=33.7 if country== "italy"
	replace gini=33.3 if country== "uk"
	replace gini=38.2 if country== "us"
	
	
	gen gini1=38.5 if country== "china"
	replace gini1=32.9 if country== "japan"
	replace gini1=31.6 if  country== "korea"
	replace gini1=35.9 if country== "italy"
	replace gini1=34.8 if country== "uk"
	replace gini1=41.4 if country== "us"
	
	gen gdp=10261.7 if country== "china"
	replace gdp=40246.9 if country== "japan"
	replace gdp=31846.2 if  country== "korea"
	replace gdp=33228.2 if country== "italy"
	replace gdp=42330.1 if country== "uk"
	replace gdp=65297.5 if country== "us"
	
	gen secondary=4.3 if country== "china"
	replace secondary=80.3 if country== "japan"
	replace secondary=76.4 if  country== "korea"
	replace secondary=49.2 if country== "italy"
	replace secondary=77.1 if country== "uk"
	replace secondary=89.8 if country== "us"
	
	
	gen unemp=4.3 if country== "china"
	replace unemp=2.3 if country== "japan"
	replace unemp=4.1 if  country== "korea"
	replace unemp=9.8 if country== "italy"
	replace unemp=3.9 if country== "uk"
	replace unemp=3.8 if country== "us"
	
	merge m:1 country using "E:\Cuong - paper\COVID\country_inequality.dta"
	
	gen ratio10=highest10/lowest10 
	gen ratio20=highest20/lowest20
	
	for var qt1 qt2 qt3 qt4 qt5: gen X_gini=X*gini
	for var qt1 qt2 qt3 qt4 qt5: gen X_gini1=X*gini1
	for var qt1 qt2 qt3 qt4 qt5: gen X_ratio10=X*ratio10
	for var qt1 qt2 qt3 qt4 qt5: gen X_ratio20=X*ratio20
	for var qt1 qt2 qt3 qt4 qt5: gen X_caserate=X*caserate
	
	
	egen cluster=group(region country)
	
	gen self_employed=(labor_status==3)
	gen employed=(labor_status==1)
	gen part_employed=(labor_status==2)
	
	gen house=(current_home==1)
	gen apartment=(current_home==2)
	
	gen alone=(current_living_arrangement==1 | current_living_arrangement==5)
	
	recode industry .=0

	
	* Change behavior: changed_behaviors

	gen asia=(country=="china" | country=="japan" | country=="korea")
	tab asia

	gen female_asia = female*asia
	
	gen expendrop=(change_weekly_expenses<=2)
	gen savingrop=(change_savings<=2)
	
	* Variables means.
	for var lost_job1 lost_job2 expendrop savingrop: gen X100=X*100

	tabform lost_job1100 lost_job2100 lnlostinc lnexpowninc change_weekly_expenses change_savings expendrop100 savingrop100 using E:\covid.xls, by(female)  se vertical
	
	
	* Regression
	global demo "belief_you_got_infected belief_infected_yourarea  alone ageg2-ageg7 urban"
	global country "china italy japan korea uk self_employed employed part_employed"
	

	global demo "ageg2 ageg3 ageg4 ageg5 ageg6 ageg7 urban"
	global country "china japan korea italy uk"
	* global country " female_asia asia"

	for var belief_policy_effectiveness_1 belief_policy_effectiveness_2 belief_policy_effectiveness_3 ///
		belief_policy_effectiveness_4 belief_policy_effectiveness_5 belief_policy_effectiveness_6 belief_policy_effectiveness_7 agree_government_action: gen nX=(X<=2)
	
	for var belief_policy_effectiveness_1 belief_policy_effectiveness_2 belief_policy_effectiveness_3 ///
		belief_policy_effectiveness_4 belief_policy_effectiveness_5 belief_policy_effectiveness_6 belief_policy_effectiveness_7 agree_government_action: gen dX=(X>=4)
	
	* Index
	pca belief_policy_effectiveness_1 belief_policy_effectiveness_2 belief_policy_effectiveness_3 ///
		belief_policy_effectiveness_4 belief_policy_effectiveness_5 belief_policy_effectiveness_6 belief_policy_effectiveness_7, com(1) vce(norm) ignore
	predict index

	sum index
	replace index=(index-r(mean))/r(sd)
	sum index
	
* Regresssion here
	reg belief_policy_effectiveness_1 caserate female $demo qt1 qt2 qt3 qt4 $country, robust
		outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr replace nolabel 
		
* Table A.1

	foreach var in agree_government_action belief_policy_effectiveness_1 belief_policy_effectiveness_2 belief_policy_effectiveness_3 ///
		belief_policy_effectiveness_4 belief_policy_effectiveness_5 belief_policy_effectiveness_6 belief_policy_effectiveness_7 {	
		reg `var' caserate female $demo qt1 qt2 qt3 qt4 $country, robust
		outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr append nolabel 
	}

	
* Table A.2
	foreach var in agree_government_action index {
			reg `var' caserate female $demo qt1 qt2 qt3 qt4 qt1_gini qt2_gini qt3_gini qt4_gini $country, robust 
			outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr append nolabel 
	}
	
	foreach var in agree_government_action index {
			reg `var' caserate female $demo qt1 qt2 qt3 qt4 qt1_gini1 qt2_gini1 qt3_gini1 qt4_gini1 $country, robust 
			outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr append nolabel 
	}
	
	
* Descriptive analysis
* Table A.3

	tab1 belief_policy_effectiveness_1 belief_policy_effectiveness_2 belief_policy_effectiveness_3 ///
		belief_policy_effectiveness_4 belief_policy_effectiveness_5 belief_policy_effectiveness_6 belief_policy_effectiveness_7 agree_government_action
		
		
* Table A.4 		
	sum dbelief_policy_effectiveness_1 dbelief_policy_effectiveness_2 dbelief_policy_effectiveness_3 ///
		dbelief_policy_effectiveness_4 dbelief_policy_effectiveness_5 dbelief_policy_effectiveness_6 dbelief_policy_effectiveness_7 dagree_government_action 
	
	sum belief_policy_effectiveness_1 belief_policy_effectiveness_2 belief_policy_effectiveness_3 ///
		belief_policy_effectiveness_4 belief_policy_effectiveness_5 belief_policy_effectiveness_6 belief_policy_effectiveness_7 agree_government_action 
	
	table country, c(mean gini mean caserate mean agree_government_action mean  belief_policy_effectiveness_1 mean belief_policy_effectiveness_2) row col format(%5.2f)
	
	table country, c(mean ratio10 mean ratio20) row col format(%5.2f)
	
	table country, c(mean belief_policy_effectiveness_3 mean belief_policy_effectiveness_4 mean belief_policy_effectiveness_5 mean belief_policy_effectiveness_6 ///
		mean belief_policy_effectiveness_7) row col format(%5.2f)
	
	
* Table A.5	

	* By country
	local i=1
	
	while `i'<=6 {
	
	foreach var in index agree_government_action {	
		
		
		reg `var' caserate female $demo qt1 qt2 qt3 qt4 if group==`i', robust
		
			outreg2 using E:\governance_country.xls, se bdec(4) sdec(4) coefastr append nolabel 
		
		}
		
		local i=`i'+1
	}
	
	
	
* Table A.6
	* Mechanisms
	foreach var in lost_job1 lost_job2 change_weekly_expenses change_savings ///
		pos_nonfin_freetime pos_nonfin_lesspolution neg_nonfin_troublesleep neg_nonfin_boredom neg_nonfin_conflicts {	
		reg `var' caserate female $demo qt1 qt2 qt3 qt4 $country, robust
		outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr append nolabel 
	}

* Table A.7
	foreach var in lost_job1 lost_job2 change_weekly_expenses change_savings ///
		pos_nonfin_freetime pos_nonfin_lesspolution neg_nonfin_troublesleep neg_nonfin_boredom neg_nonfin_conflicts {	
		reg agree_government_action `var' caserate female $demo qt1 qt2 qt3 qt4 $country, robust
		outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr append nolabel 
	}
	
* Mediation analysis (Figure 4)
	foreach var in lost_job1 lost_job2 change_weekly_expenses change_savings ///
		pos_nonfin_freetime pos_nonfin_lesspolution neg_nonfin_troublesleep neg_nonfin_boredom neg_nonfin_conflicts {	
		
		medeff (regress `var' caserate female $demo qt1 qt2 qt3 qt4 $country)  ///
			(regress  agree_government_action `var' caserate female $demo qt1 qt2 qt3 qt4 $country), mediate(`var') treat(qt1) vce(robust)
	
	} 
	
	
	
	
	
* Table B.1	
	* Order logit: report odd ratio
	foreach var in belief_policy_effectiveness_1 belief_policy_effectiveness_2 belief_policy_effectiveness_3 ///
		belief_policy_effectiveness_4 belief_policy_effectiveness_5 belief_policy_effectiveness_6 belief_policy_effectiveness_7 agree_government_action  {	
		ologit `var' caserate female $demo qt1 qt2 qt3 qt4 $country, robust or
		outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr append nolabel  eform  cti(odds ratio) addstat(R-squared, e(r2_p))
	}
	
	* Get P-value 
	foreach var in belief_policy_effectiveness_1 belief_policy_effectiveness_2 belief_policy_effectiveness_3 ///
		belief_policy_effectiveness_4 belief_policy_effectiveness_5 belief_policy_effectiveness_6 belief_policy_effectiveness_7 agree_government_action  {	
		ologit `var' caserate female $demo qt1 qt2 qt3 qt4 $country, robust or
		outreg2 using E:\governance_pvalue.xls, pvalue bdec(4) pdec(5) coefastr append nolabel 
	}
	
	
* Table B.2

	* Bottom quintile
	gen qt12=(qt1==1 | qt2==1)
	gen qt123=(qt1==1 | qt2==1 | qt3==1)
	gen qt1234=(qt1==1 | qt2==1 | qt3==1 | qt4==1)
	
	for var qt12 qt123 qt1234: gen X_gini=X*gini
	
	foreach var in agree_government_action index {
		reg `var' caserate female $demo qt1 qt1_gini $country, robust 
			outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr append nolabel 
			
		reg `var' caserate female $demo qt12 qt12_gini $country, robust 
			outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr append nolabel 
			
			
		reg `var' caserate female $demo qt123 qt123_gini $country, robust 
			outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr append nolabel 
			
		reg `var' caserate female $demo qt1234 qt1234_gini $country, robust 
			outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr append nolabel 
	}
	
	
	
	
* Table B.3
	foreach var in agree_government_action index {	
		reg `var' caserate female $demo qt1 qt2 qt3 qt4 qt1_ratio10 qt2_ratio10 qt3_ratio10 qt4_ratio10 $country, robust
		outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr append nolabel 
	}
	
	foreach var in agree_government_action index {	
		reg `var' caserate female $demo qt1 qt2 qt3 qt4 qt1_ratio20 qt2_ratio20 qt3_ratio20 qt4_ratio20 $country, robust
		outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr append nolabel 
	}
	
	
* robustness check
********** OLS *****************

* Table B.4

	* with control variables
	gen lngdp=ln(gdp)
	foreach var in agree_government_action belief_policy_effectiveness_1 belief_policy_effectiveness_2 belief_policy_effectiveness_3 ///
		belief_policy_effectiveness_4 belief_policy_effectiveness_5 belief_policy_effectiveness_6 belief_policy_effectiveness_7 {	
		reg `var' caserate female $demo qt1 qt2 qt3 qt4 lngdp gini unemp second, robust
		outreg2 using E:\governance.xls, se bdec(4) sdec(4) coefastr append nolabel 
	}
	
	
log close



